<?php

	class Security_proxy extends Model
	{
		public function __construct()
		{
			parent::__construct();
		}
		
		
		public function authenticate( $un, $pw )
		{
			$getUser = $this->db->query('
											SELECT		p.person_id,
														p.password
											FROM		person p
											WHERE		trim(p.person_name) = ' . $this->db->escape( trim($un) ) . '
											AND			p.enabled = 1
											LIMIT		1	
							 			');

			$personId = 0;

			if( $getUser->num_rows() == 1 )
			{
				$this->load->library('encrypt');

				$decodedDbPw = $this->encrypt->decode( $getUser->row()->password );
									
				if( trim($decodedDbPw) == trim($pw) )
				{
					$personId = $getUser->row()->person_id;
				} 
				
			}
			
			return $personId;
		}
		
	}
?>